<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>FH Admin</title>
  <!-- HTML5 Shim and Respond.js IE10 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 10]>
  <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
  <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
  <![endif]-->
  <!-- Meta -->
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="author" content="FH Admin QQ313596790" />

  <link rel="icon" href="/apkversion/images/favicon.ico" type="image/x-icon">
  <link rel="stylesheet" href="/apkversion/fonts/fontawesome/css/fontawesome-all.min.css">
  <link rel="stylesheet" href="/apkversion/css/style.css">


  <!-- vue -->
  <script src="/apkversion/js-vue/vue.js"></script>
  <!--全局配置-->
  <script src="/apkversion/js-v/config.js"></script>
  <link href="https://cdn.bootcdn.net/ajax/libs/iview/3.5.4/styles/iview.css" rel="stylesheet">
  <!-- 引入组件库 -->
  <script src="https://cdn.bootcdn.net/ajax/libs/iview/3.5.4/iview.min.js"></script>

</head>

<body style="background-color: white">

<!-- [加载状态 ] start -->
<div class="loader-bg">
  <div class="loader-track">
    <div class="loader-fill"></div>
  </div>
</div>
<!-- [ 加载状态  ] End -->

<!-- [ 主内容区 ] start -->
<div class="pcoded-wrapper" id="app">
  <div class="pcoded-content">
    <div class="pcoded-inner-content">
      <div class="main-body">
        <div class="page-wrapper">
          <!-- [ Main Content ] start -->
          <div class="row">

            <div style="width: 100%;">
              <div id="showform">
                <div class="input-group input-group-sm mb-3" style="margin-top: -10px;">
                  <div class="input-group-prepend">
												<span class="input-group-text" style="width: 79px;"><span
                          style="width: 100%;">版本号</span></span>
                  </div>
                  <input type="text" class="form-control" ref="VERSION" id="VERSION" v-model="pd.VERSION" maxlength="30" placeholder="这里输入版本号" title="备注2">
                </div>
                <div class="input-group input-group-sm mb-3" style="margin-top: -10px;">
                  <div class="input-group-prepend">
												<span class="input-group-text" style="width: 79px;"><span
                          style="width: 100%;">平台</span></span>
                  </div>
                  <input type="text" class="form-control" ref="PLAT" id="PLAT" v-model="pd.PLAT" maxlength="30" placeholder="1：安卓 2：苹果" title="备注2">
                </div>
                <div class="input-group input-group-sm mb-3" style="margin-top: -10px;">
                  <div class="input-group-prepend">
												<span class="input-group-text" style="width: 79px;"><span
                          style="width: 100%;">文件上传</span></span>
                  </div>
                  <Upload
                    ref="upload"
                    :max-size="819200"
                    :on-success="uploadSuccess"
                    :on-exceeded-size="handleMaxSize"
                    :action="actionPath">
                    <div style="padding: 20px 0">
                      <Icon type="ios-cloud-upload" size="32" style="color: #3399ff"></Icon>
                      <p>点击或将文件拖拽到这里上传</p>
                    </div>
                  </Upload>
                </div>

                <div class="input-group" style="margin-top:10px;background-color: white">
											<span style="width: 100%;text-align: center;">
							            		<a class="btn btn-light btn-sm" v-on:click="save">保存</a>
							            		<a class="btn btn-light btn-sm" onclick="parent.window.diag.close()">取消</a>
							            	</span>
                </div>
              </div>
              <!-- [加载状态 ] start -->
              <div id="jiazai" style="display:none;margin-top:50px;">
                <div class="d-flex justify-content-center">
                  <div class="spinner-border" style="width: 3rem; height: 3rem;" role="status">
                    <span class="sr-only">Loading...</span>
                  </div>
                </div>
              </div>
              <!-- [ 加载状态  ] End -->
            </div>

          </div>
          <!-- [ Main Content ] end -->
        </div>
      </div>
    </div>
  </div>
</div>
<!-- [ 主内容区 ] end -->

<script type="text/javascript" src="/apkversion/js/jquery-1.7.2.js"></script>
<script type="text/javascript" src="/apkversion/js/pre-loader.js"></script>
<script src="/apkversion/plugins/sweetalert/js/sweetalert.min.js"></script>


<!-- 表单验证提示 -->
<script src="/apkversion/js/jquery.tips.js"></script>

<script type="text/javascript">
  var vm = new Vue({
    el: '#app',

    data: {
      APKVERSION_ID: '', //主键ID
      pd: [], //存放字段参数
      msg: 'add',
      actionPath:"/api/apkversion/apkUpload"
    },

    methods: {
      uploadSuccess (response, file, fileList) { // 文件上传回调 上传成功后删除待上传文件
        console.log("=========uploadSuccess=============")
        //console.log(response.url) // 后端返回数据
        this.pd.FILENAME=response.data.fileName;
        //console.log("=========uploadSuccess=============")
      },
      handleMaxSize (file) {
        this.$Notice.warning({
          title: '超出文件大小限制',
          desc: '文件 ' + file.name + ' 太大，不能超过 80M。'
        });
      },
      //初始执行
      init() {
        var FID = this.getUrlKey('FID'); //当接收过来的FID不为null时,表示此页面是修改进来的
        if(null != FID) {
          this.msg = 'edit';
          this.APKVERSION_ID = FID;
          this.getData();
        }
        setTimeout(function() {
          vm.getDict();
        }, 200);
      },

      //去保存
      save: function() {

        if(this.pd.FILENAME == '' || this.pd.FILENAME == undefined) {
          $("#FILENAME").tips({
            side: 3,
            msg: '请输入备注1',
            bg: '#AE81FF',
            time: 2
          });
          this.pd.FILENAME = '';
          this.$refs.FILENAME.focus();
          return false;
        }
        if(this.pd.VERSION == '' || this.pd.VERSION == undefined) {
          $("#VERSION").tips({
            side: 3,
            msg: '请输入版本号',
            bg: '#AE81FF',
            time: 2
          });
          this.pd.VERSION = '';
          this.$refs.VERSION.focus();
          return false;
        }
        if(this.pd.PLAT == '' || this.pd.PLAT == undefined) {
          $("#PLAT").tips({
            side: 3,
            msg: '请输入平台，1表示安卓，2表示ios',
            bg: '#AE81FF',
            time: 2
          });
          this.pd.VERSION = '';
          this.$refs.VERSION.focus();
          return false;
        }

        $("#showform").hide();
        $("#jiazai").show();

        //发送 post 请求提交保存
        $.ajax({
          xhrFields: {
            withCredentials: true
          },
          type: "POST",
          url: '/api/apkversion/' + this.msg,
          data: {
            APKVERSION_ID: this.APKVERSION_ID,
            FILENAME: this.pd.FILENAME,
            VERSION: this.pd.VERSION,
            PLAT: this.pd.PLAT,
            tm: new Date().getTime()
          },
          dataType: "json",
          success:

            function(data) {
              if("success" == data.data.result) {
                swal("", "保存成功", "success");
                setTimeout(function() {
                  parent.window.Dialog.close(); //关闭弹窗
                }, 1000);
              } else if("exception" == data.data.result) {
                showException("APK版本管理", data.data.exception); //显示异常
                $("#showform").show();
                $("#jiazai").hide();
              }
            }
        }).
        done().fail(function() {
          swal("登录失效!", "请求服务器无响应，稍后再试", "warning");
          $("#showform").show();
          $("#jiazai").hide();
        });
      },

      //根据主键ID获取数据
      getData: function() {
        //发送 post 请求
        $.ajax({
          xhrFields: {
            withCredentials: true
          },
          type: "POST",
          url:  '/api/apkversion/goEdit',
          data: { APKVERSION_ID: this.APKVERSION_ID, tm: new Date().getTime() },
          dataType: "json",
          success: function(data) {
            if("success" == data.data.result) {
              vm.pd = data.pd; //参数map
            } else if("exception" == data.data.result) {
              showException("APK版本管理", data.data.exception); //显示异常
              $("#showform").show();
              $("#jiazai").hide();
            }
          }
        }).done().fail(function() {
          swal("登录失效!", "请求服务器无响应，稍后再试", "warning");
          $("#showform").show();
          $("#jiazai").hide();
        });
      },

      //获取数据字典数据
      getDict: function() {},

      //根据url参数名称获取参数值
      getUrlKey: function(name) {
        return decodeURIComponent(
          (new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null;
      }

    },

    mounted() {
      this.init();
    }
  })
</script>

</body>

</html>
